
var prefix = "/api/orderInfo";
$(function() {
	load();

	$("#derive").click(function (){
		layer.confirm('确认要导出充值列表吗？', {
			btn: ['确认', '取消'] //可以无限个按钮
		}, function(index, layero){
			layer.closeAll();
			window.location.href = `/api/orderInfo/downloadImportStu?starTime=${$('#starTime').val()}&endTime=${$('#endTime').val()}`
		}, function(index){

		});
	})

});

var pages = 1;
function load() {

	layui.use(['table','laydate'], function(){
		var table = layui.table;
		var laydate = layui.laydate
			$ = layui.$;

		let myStartDate,myEndDate;
		myStartDate=laydate.render({
			elem: "#starTime",
			trigger: 'click',
			type: 'datetime',
			max:"9999-12-31 24:50:14",
			done: function (value, dates) {
				myEndDate.config.min ={
					year:dates.year,
					month:dates.month-1, //关键
					date: dates.date,
					hours: dates.hours,
					minutes: dates.minutes,
					seconds : dates.seconds
				};
			}
		});
		myEndDate=laydate.render({
			elem: "#endTime",
			trigger: 'click',
			type: 'datetime',
			min:"1888-01-01 00:00:00",
			done: function (value, dates) {
				myStartDate.config.max={
					year:dates.year,
					month:dates.month-1,//关键
					date: dates.date,
					hours: dates.hours,
					minutes: dates.minutes,
					seconds : dates.seconds
				}
			}
		});







		// 创建渲染实例
		table.render({
			elem: '#exampleTable'
			,id:'exampleTable'
			,method:'POST'
			// prefix
			,url: prefix + "/list" // 此处为静态模拟数据，实际使用时需换成真实接口
			,cellMinWidth: 80
			, page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
				layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
				, curr: pages //设定初始在第 5 页
				, groups: 5 //只显示 1 个连续页码
				, limit : 15
				, limits : [15,30,50,100,200]
			}
			,request:{
				pageName: 'current',
				limitName: 'number'
			}
			,where: {
				beginTime: $("#starTime").val() ,
				endTime: $("#endTime").val()
			}
			,defaultToolbar: false
			,loading: false
			,cols: [[
				{
					field : 'name',
					align : 'center',
					title : '充值人'
				},
				{
					field : 'createTime',
					align : 'center',
					title : '充值时间'
				},
				{
					field: 'totalFee',
					align : 'center',
					title: '充值金额'
				},
				{
					field : 'orderRemark',
					align : 'center',
					title : '备注'
				},
				{
					title : '操作',
					field : 'id',
					align : 'center',
					templet : function(d) {

						let i ;

						if( d.status != 0 ){
							i = `<a class="btn btn-primary btn-sm " href="#" mce_href="#" title="禁用" onclick="changeState(${d.id},1)">启用</a>`
						}else{
							i = `<a class="btn btn-primary btn-sm " href="#" mce_href="#" title="禁用" onclick="changeState(${d.id},2)">禁用</a>`
						}

						var e = '<a  class="btn btn-primary btn-sm " href="#" mce_href="#" title="详情" onclick="lookInfo(\''
							+ d.id
							+ '\')"><i class="fa fa-send"></i></a> ';

						var ss = '<a class="btn btn-success btn-sm" href="#" title="删除"  mce_href="#" onclick="remove(\''
							+ d.id
							+ '\')"><i class="fa fa-remove"></i></a>';
						return e;
					}
				}
			]]
			,response: {
				statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
			}
			,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
				$("#sum").html(res.data.records[0].grossIncome)
				if( res.code != 0 ){
					return false;
				}
				return {
					"code": res.code, //解析接口状态
					"msg": res.msg, //解析提示文本
					"count": res.data.total, //解析数据长度
					"data": res.data.records[0].orderInfoPage //解析数据列表
				};
			}
			,jump: function (obj, first) {
				//首次不执行
				if (!first) {
					pages = obj.curr
				}
			}
			,error: function(res, msg){
				console.log(res, msg)
			}

			,done: function (res){
				layer.close()
				hindLoading()
			}
		});

		var $ = layui.$, active = {
			reload: function(){
				//执行重载
				table.reload('exampleTable', {
					page: {
						curr: 1 //重新从第 1 页开始
					}
					,where: {
						starTime: $('#starTime').val(),
						endTime: $('#endTime').val()
					}
				});
			}
		};

		$('.demoTable .layui-btn').on('click', function(){
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		//触发表格复选框选择
		table.on('checkbox(test)', function(obj){
			console.log(obj)
		});

		//触发表格单选框选择
		table.on('radio(test)', function(obj){
			console.log(obj)
		});

	});

}

function lookInfo(id) {
	sessionStorage.setItem('infoId',id)
	layer.open({
		type : 2,
		title : '充值详情',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '520px' ],
		content : '/jzweb/jazUserRecharge/info' // iframe的url
	});
}

